<?php
/**
 * Created by PhpStorm.
 * User: 14775
 * Date: 2017/9/27
 * Time: 11:38
 */

namespace Api\Controller;


use Common\Controller\HomebaseController;
use Common\Model\MembersModel;

class SyncintegralController extends HomebaseController
{

    public function dosync()
    {
        $api_users = C('API_USERS');
        //验证
        $params = I('');
        $api_sign = $params['sign'];
        $api_appid = $params['apiid'];
        $api_appsecret = $api_users[$api_appid];

        unset($params['sign']);
        $params['apisecret'] = $api_appsecret;
        ksort($params);
        $str_parmas = http_build_query($params);

        if ($api_sign == md5($str_parmas)) {
            //=============同步会员积分==========>>>>>>>>>>>>
            $integral = $params['integral'];
            $member_code = $params['member_code'];

            $memberModel = new MembersModel();
            $member = $memberModel->getMemberByCode($member_code);
            if($member){
                $memberModel->syncIntegral($member_code, $integral);
                $this->ajaxReturn(array('status' => 200, 'message' => '同步成功'));
            }
            $this->ajaxReturn(array('status' => 0, 'message' => '会员数据不存在'));

            //<<<<<<<<<<<<<<=====================================
        } else {
            $this->ajaxReturn(array('status' => 0, 'message' => '验签失败'));
        }
        $this->ajaxReturn(array('status' => 0, 'message' => '系统错误'));
    }

}